package com.xxk.rocket.star.core.annotation.impl;

import com.xxk.rocket.star.annotation.StargatePullBatchSize;
import com.xxk.rocket.star.core.annotation.AbsProcessAnnotationConsume;
import com.xxk.rocket.star.core.dto.StargateConsumeBaseDTO;
import com.xxk.rocket.star.core.exception.StargateException;

import java.lang.reflect.Method;

public class StargatePullBatchSizeProcessAnnotation
        extends AbsProcessAnnotationConsume<StargateConsumeBaseDTO> {

  @Override
  protected void processConsume(StargateConsumeBaseDTO stargateConsumeBaseDTO, Class aClass,
                                Object o,
                                Method method) throws Throwable {
    StargatePullBatchSize stargatePullBatchSize = null;
    if (method == null) {
      stargatePullBatchSize = (StargatePullBatchSize) aClass
              .getAnnotation(StargatePullBatchSize.class);
    } else {
      stargatePullBatchSize = method.getAnnotation(StargatePullBatchSize.class);
    }
    if (stargatePullBatchSize == null) {
      return;
    }
    if (stargatePullBatchSize.value() < 1 || stargatePullBatchSize.value() > 1024) {
      throw new StargateException("StargatePullBatchSize 1<value<1024");
    }
    stargateConsumeBaseDTO.setPullBatchSize(stargatePullBatchSize.value());
  }
}
